package com.gym.controller.user;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.gym.VO.ResultVO;
import com.gym.form.user.LoginForm;
import com.gym.service.user.LoginService;

@Controller
@RequestMapping(value = "login")
public class LoginController {

	@Autowired
	private LoginService loginService;

	@RequestMapping(value = "login", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	@ResponseBody
	public ResultVO login(@RequestBody LoginForm loginForm) {
		return this.loginService.login(loginForm);
	}

	@RequestMapping(value = "logout")
	@ResponseBody
	public void logout() {
		Subject subject = SecurityUtils.getSubject();
		if (subject != null) {
			try {
				subject.logout();
			} catch (Exception ex) {
			}
		}
	}

}
